// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  if (event.Content === '我要进群') {
    await cloud.openapi.customerServiceMessage.send({
      touser: wxContext.OPENID,
      msgtype: 'image',
      image: {
        media_id: 'GqD-IC_PRD96AUSUHT1BPDsiuMsOLSHI4knAPwUq7nX-bTnYsJi2dSmGr_IRBiWX'
      }
    })
    return 'success'
  } else if (event.Content === '666') {
    await cloud.openapi.customerServiceMessage.send({
      touser: wxContext.OPENID,
      msgtype: 'image',
      image: {
        media_id: 'FMQdnViQWjRjlvvZUv0afFVSQYkS6U6YjzA0weqJdOXbkw1pL11kA2Pkv9f_TghJ'
      }
    })
    return 'success'
  } else {
    return {
      MsgType: 'transfer_customer_service',
      ToUserName: `${wxContext.OPENID}`,
      FromUserName: 'gh_22ec8533f225',
      CreateTime: event.CreateTime,
    }
  }
}